import 'dart:ui';

import 'package:flutter/material.dart';
import 'res/listData.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("有点f麻烦"),
        ),
        body: HomeContent(),
      ),
    );
  }
}

class HomeContent extends StatelessWidget {
  Widget setData(context, index) {
    return ListTile(
      leading: Image.network(mListData[index]["imageUrl"]),
      title: Text(mListData[index]["title"]),
      subtitle: Text(mListData[index]["author"]),
    );
  }

  // Widget setData() {
  //   GridTile();
  // }

  List<Widget> getData() {
    var mlist = mListData.map((value) {
      return Container(
        child: Column(
          children: <Widget>[
            Image.network(value["imageUrl"]),
            SizedBox(
              height: 10,
            ),
            Text(
              value["title"],
              textAlign: TextAlign.center,
            )
          ],
        ),
        decoration: BoxDecoration(
            border: Border.all(color: Colors.yellow, width: 1),
            borderRadius: BorderRadius.all(Radius.circular(8))),
      );
    });
    return mlist.toList();
  }

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      padding: EdgeInsets.all(10),
      crossAxisSpacing: 10.0,
      mainAxisSpacing: 10.0,
      // childAspectRatio: 0.7,
      crossAxisCount: 2,
      children: this.getData(),
    );
  }
}
